<template>
  <div>
    <el-form :model="innerData" :rules="rules" ref="ruleForm" label-width="130px">
      <el-form-item label="优惠券类型" prop="series_id">
        <el-select @change="getName" v-model="innerData.series_id" placeholder="请选择">
          <el-option
            v-for="item in seriesList"
            :key="item.series_id"
            :label="item.series_name"
            :value="item.series_id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="可领取用户" v-if="hasMore">
        <el-select v-model="innerData.grant_type" placeholder="请选择">
          <el-option
            v-for="item in comboList"
            :key="item.member_id"
            :label="item.member_name"
            :value="item.member_id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="优惠券名称" >
        <el-input
          class="w400"
          placeholder="请输入"
          v-model="innerData.coupon_name"
        ></el-input>
      </el-form-item>
      <el-form-item label="几日游以上可用">
        <el-input
          type="number"
          class="w400"
          placeholder="请输入"
          v-model="innerData.trip_count"
          autocomplete="off"
        ></el-input>
         天（包含≥）
      </el-form-item>
      <el-form-item label="单笔满">
        <el-input
          type="number"
          class="w400"
          placeholder="请输入"
          v-model="innerData.full_money"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="立减">
        <el-input
          type="number"
          class="w400"
          placeholder="请输入"
          v-model="innerData.reduction_money"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="发放总量">
        <el-input
          type="number"
          class="w400"
          placeholder="请输入"
          v-model="innerData.sum_count"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="开始时间" v-if="hasMore">
        <el-date-picker
          v-model="innerData.start_time"
          value-format="timestamp"
          type="date"
          placeholder="选择日期" >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" v-if="hasMore">
        <el-date-picker
          v-model="innerData.end_time"
          value-format="timestamp"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="加入领券中心" v-if="hasMore">
        <el-radio-group v-model="innerData.is_core">
          <el-radio label="1">是</el-radio>
          <el-radio label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="权益说明" >
        <quilleditor v-model="innerData.coupon_content" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import quilleditor from 'components/quilleditor';
import { getSeriesAll } from 'api/lineManagement/seriesMgAPI';
import memberComboAPI from 'api/memberManagement/memberComboAPI';

export default {
  components: {
    quilleditor
  },
  props: {
    formData: {
      default: {}
    },
    hasMore: {
      default: false
    }
  },
  computed: {
    // innerData(){
    //   return {...this.formData}
    // }
  },
  watch: {
    formData: {
      handler: function(val) {
        this.innerData = val
        // this.$emit('update:formData', this.innerData)
      },
      // deep: true,
      immediate: true
    },
    innerData: {
      handler: function(val) {
        // console.log(val)
        this.$emit('update:formData', val)
      },
      deep: true
    },
    // imgs: {
    //   handler: function() {
    //     this.innerData.benefit_img = this.imgs.join(',')
    //   },
    //   deep: true
    // }
  },
  data() {
    return {
      imgs: [],
      rules: {},
      innerData: {},
      seriesList: [],
      comboList: []
    }
  },
  methods: {
    getName(val) {
      this.innerData.series_name = this.seriesList.find(item => item.series_id === val).series_name
    },
    async _getSeriesAll() {
      let res = await getSeriesAll();
      res.rData.unshift({series_id: '0', series_name: '所有线路'})
      this.seriesList = res.rData;
    },
    // 获取会员套餐
    async getComboList() {
      memberComboAPI('getMemberConfigAllList').then(res => {
        let arr = res.rData.concat([{member_id: '0',member_name: '所有人'}, {member_id: '9999',member_name: '新用户'}])
        this.comboList = arr
      })
    }
  },
  created() {
    this._getSeriesAll()
    if(this.hasMore) {
      this.getComboList()
    }
  }
}
</script>

<style lang="scss" scoped>
.w400{
  width: 400px;
}
</style>